import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import TableControls from '#cpt/temp/TableControls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 			= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 		= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms : [
			{ label: '医院名称',		name: 'hosp_id',	type: 'select', loading:true, onValue:({ rows }) => {
				this.model.hosp_name = rows ? rows.name : ''
			}  },
			{ label: '医院等级',		name: 'level',		type: 'select', idStr:'code' },
		],
	}
	
	model = {}
	
	componentDidMount(){
		
		this.getSelect()
		if(window.isInit){
		  this.fetch()
		}
	}
	// 获取下拉数据
	 getSelect = async () => {
	  const { forms } = this.state
	  $cache.then( async f => {
			// 医院名称
			$fn.setRow( forms, 'hosp_id', await f.getCache({ api:'hospital' }) )
			// 医院等级
			$fn.setRow( forms, 'level', await f.getDicCache({ code:39000 }) )
			this.setState({ forms })
	  })
	 }
	 
	// paging
	fetch = () => $fn.fetch.call(this,'bs-hospital/myHosp')
	
	// 表单
	cols = [
		{ title: '医院编号',			dataIndex: 'hosp_code', 		width:150 },
		{ title: '医院名称', 		dataIndex: 'hosp_name', 		width:200 },
		{ title: '医院地址', 		dataIndex: 'address', 			width:150 },
		{ title: '所属区域', 		dataIndex: 'region_name', 		width:150 },
		{ title: '医院等级',			dataIndex: 'level_name', 		width:100 },
		{ title: '送检日期', 		dataIndex: 'create_at', 		width:150 },
		TableControls.controls.call(this,{ width: 150 })
	]
	// 表格操作按钮
		table_controls = (text,{uuid}) => {
			return [
				TableControls.pushTo.call(this,'查看报告', `check-report?uuid=${uuid}`),
			]
		}
	render(){
			return (
				<>
					<Page title='我的医院' >
						{/* 搜索 */}
						{ SearchForm.call(this) }
						{/* 表格 */}
						{ Table.call(this, { isInit: window.isInit }) }
					</Page>
				</>
			)
		}
	}
	
	export default Index